#!/usr/bin/perl -w

## example script to show how to use the Java classes from
## perl.

BEGIN {
  $ENV{'CLASSPATH'} = "./SemanticModels.jar:lib/semanticvectors-1.31.jar:lib/lucene-core-3.0.1.jar";
  if(!defined($ENV{'JAVA_OPTS'})) {
    $ENV{'JAVA_OPTS'} = '-Xmx1024m';
  }

}

use 5.010;
use strict;
use warnings;
# use feature 'unicode_strings';  #requires 5.012
use Inline
  Java => 'STUDY',
  STUDY => [
    qw(
        at.ofai.sail.gate.ri.TermSearcher
        java.util.List
        java.util.Iterator
        java.util.LinkedList$ListItr
      )
  ],
  EXTRA_JAVA_ARGS => $ENV{'JAVA_OPTS'},
  AUTOSTUDY => 1;
use Inline::Java qw(cast) ;

binmode(STDOUT,":utf8");

my $s = at::ofai::sail::gate::ri::TermSearcher->new(
  "index/termvectors.bin","index/index");

my $rets = $s->getAllTerms();
my $itorig = $rets->iterator();
my $it = cast('java.util.Iterator',$itorig);

while($it->hasNext()) {
  my $term = $it->next();
  print "$term\n";
}


